/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package scheduler.fixtures;

import java.util.ArrayList;
import java.util.Collection;
import se392.ateam2006.meetingmgmt.MeetingMgmtRemote;

/**
 *
 * @author Caroline
 */
class SubmitEquipmentRequestForParticipantForMeeting extends fit.RowFixture {

    private MeetingMgmtRemote meetingManage;
    private String userId;
    private String meetingId;

    public SubmitEquipmentRequestForParticipantForMeeting(MeetingMgmtRemote meetingManage, String userId, String meetingId) {
        this.meetingManage = meetingManage;
        this.userId = userId;
        this.meetingId = meetingId;
    }

    @Override
    public Object[] query() throws Exception {
        String equipment = meetingManage.getEquipmentForMeeting(userId, meetingId);
        String[] equipArray = equipment.split(",");
        ArrayList<EquipmentShell> resolvedEquipment = new ArrayList<EquipmentShell>();
        for (int i = 0; i < equipArray.length; i++) {
            while (resolvedEquipment.iterator().hasNext()) {
                EquipmentShell temp = resolvedEquipment.iterator().next();
                if (temp.equipment.equalsIgnoreCase(equipArray[i])) {
                    int indexOfCurrentEquip = resolvedEquipment.indexOf(temp);
                    resolvedEquipment.get(indexOfCurrentEquip).number++;
                } else {
                    resolvedEquipment.add(new EquipmentShell(equipArray[i], 1));
                }
            }
        }

        return resolvedEquipment.toArray();
    }

    @Override
    public Class getTargetClass() {
        return EquipmentShell.class;
    }
}
